<?php

namespace application\pay\controller;

use application\admin\controller\base as auth;
use ticky\request;
use ticky\response;
use application\pay\model\payment;

//支付操作类
class pay extends auth {

    /**
     * 列表
     */
    public function index() {
        $ret = db('pay_mode a')
                ->field('a.*')
                ->newpage();
        $this->assign('page', $ret['page']);
        $this->assign('items', $ret['items']);
        $this->display('pay_list');
    }

    /**
     * 编辑
     */
    public function edit() {
        if (request::isPost()) {
            $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
            $data['enabled'] = intval($_POST['enabled']);
            $data['config'] = array2string($_POST['config']);
            db('pay_mode')->where(array('id' => $id))->update($data);
            showmsg('修改成功', '/pay/pay');
        } else {
            $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
            $data = db('pay_mode')->where(array('id' => $id))->find();
            $config = string2array($data['config']);
            $result = array_merge($data, $config);

            $this->assign('id', $id);
            $this->assign('item', $result);
            //debug($data['template']);
            $this->display($data['template']);
        }
    }

}
